# -*- coding = utf-8 -*-
# @Time    : 2025/3/26 下午9:21
# @Author  : yqk
# @File    : xpath.py
# @Software: PyCharm

from lxml import etree

#读入本地的 xml html 文件。
xml = etree.parse('hello.html')
# print(etree.tostring(xml).decode())

with open('xpath-study.html', 'r', encoding='utf-8') as f:
    text = f.read()
html = etree.HTML(text)
# result = html.xpath('/html/head/title/text()') #/表示从根节点开始
# result2 = html.xpath('//title/text()') #//表示从任意节点开始
# print(result)

#通过属性选择器选择节点
result = html.xpath('//div[@class="song"]')
print(result)


